USE [SONALIKA_BGK]
GO

/****** Object:  StoredProcedure [dbo].[SpDeliveryChallanrpt]    Script Date: 04/06/2014 16:22:45 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SpDeliveryChallanrpt]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[SpDeliveryChallanrpt]
GO

USE [SONALIKA_BGK]
GO

/****** Object:  StoredProcedure [dbo].[SpDeliveryChallanrpt]    Script Date: 04/06/2014 16:22:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO




CREATE PROC [dbo].[SpDeliveryChallanrpt]-- 2
@DC_NO INT
AS
BEGIN
SELECT 
        DC_NO
       ,DC_DATE
       ,SELL_TYPE
       ,TRACTOR_ENGINE_NO
       ,TRACTOR_CHASSIS_NO
       ,TRACTOR_MODEL_NAME
        ,DC.CUSTOMER_ID AS CUSTOMER_ID
        ,SI.SALES_INVOICE_ID
        ,HYPOTHETICATION 
 FROM DELIVERY_CHALAN DC
     LEFT OUTER JOIN TRACTOR_PURCHASES TP ON TP.TRACTOR_ID=DC.TRACTOR_ID
     LEFT OUTER JOIN TRACTOR_MODELS TM ON TM.TRACTOR_MODEL_ID=TP.TRACTOR_MODEL_ID
     LEFT OUTER JOIN SALES_INVOICES SI ON SI.SALES_INVOICE_ID=DC.SALES_INVOICE_ID
     
 WHERE SELL_TYPE=(SELECT MASTER_ID FROM MASTER WHERE MASTER_VALUE='TRACTOR')AND DC.DC_NO=@DC_NO
 ORDER BY TRACTOR_ENGINE_NO DESC
END

GO


